Use case: SMARTCARD RX IT process

Sequence diagram

SMARTCARD receive IT process

  @startuml
  participant " Application" as p1
  participant "HAL SMARTCARD driver" as p2
  participant "SMARTCARD_IRQHandler" as p3

  == initialization and configuration ==
  == Smartcard HAL Receive IT ==

  p1->p2: <color: green> HAL_SMARTCARD_Receive_IT(&hsmartcard, aRxBuffer, DATA_TO_RECEIVE_SIZE)
  note over p2 #00FF00
  Receiving data ongoing
  end note
  p2-->p1: HAL_OK
  p3<-: SMARTCARD data interrupt
  p3->p2: HAL_SMARTCARD_IRQHandler
  note over p2 #FFFF99
  All data (Size == hsmartcard->RxXferCount) have been received
  end note
  note over p2 #00FF00
  End of receiving data
  end note
  p2->p1: HAL_SMARTCARD_RxCpltCallback(hsmartcard->RxXferCount)

  @enduml

Code snippet

HAL1

HAL2

#define DATA_TO_RECEIVE_SIZE       256

uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];

SMARTCARD_HandleTypeDef hsmartcard;


/* Ensure that all required peripherals
  (USART, GPIO, NVIC etc.) are configured properly
/*
...
*/

/* Smartcard register Receive complete user callback */
HAL_SMARTCARD_RegisterCallback(&hsmartcard, HAL_SMARTCARD_RX_CB_ID,
                               Smartcard_RxCpltCallback);

/* Start a Smartcard Process in interruption mode */
HAL_SMARTCARD_Receive_IT(&hsmartcard, aRxBuffer,
                        DATA_TO_RECEIVE_SIZE);
#define DATA_TO_RECEIVE_SIZE       256

uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];

hal_smartcard_handle_t hsmartcard;


/* Ensure that all required peripherals
  (USART, GPIO, NVIC etc.) are configured properly
/*
...
*/

/* Smartcard register Receive complete user callback */
HAL_SMARTCARD_RegisterRxCpltCallback(&hsmartcard, Smartcard_RxCpltCallback);


/* Start a Smartcard Process in interruption mode */
HAL_SMARTCARD_Receive_IT(&hsmartcard, aRxBuffer,
                        DATA_TO_RECEIVE_SIZE);

Key changes

  1. HAL2 uses the SMARTCARD handle type hal_smartcard_handle_t.

  2. HAL2 provides a dedicated receive-complete callback registration API (HAL_SMARTCARD_RegisterRxCpltCallback).